package com.kritsana_ding.startrax;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.StrictMode;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity implements OnClickListener {

	public TextView textViewWelcome;
	public Button button;

	public String[] welcome = { "W", "e", "l", "c", "o", "m", "e", " ", "T","o", " ", "S", "t", "a", "r", " ", "T", "r", "a", "x" };
	public String txt = "";
	public int index = 0;

	public Handler handler1 = new Handler();
	public Handler handler2 = new Handler();
	public Handler handler3 = new Handler();

	public boolean status_task_2 = false;

	public Runnable task1 = new Runnable() {

		@Override
		public void run() {
			// TODO Auto-generated method stub
			handler1.postDelayed(this, 100);
			if (status_task_2) {
				if (index != welcome.length) {
					txt += welcome[index];
					textViewWelcome.setText(txt);
					index++;
				} else {
					status_task_2 = false;
				}
			}
		}
	};

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		// Permission StrictMode
		if (android.os.Build.VERSION.SDK_INT > 9) {
			StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
					.permitAll().build();
			StrictMode.setThreadPolicy(policy);
		}

		init();
		
		overridePendingTransition(R.anim.slide_down, R.anim.slide_up);

		status_task_2 = true;
		handler1.postDelayed(task1, 100);

		button.setOnClickListener(new OnClickListener() {			

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				//overridePendingTransition(R.anim.slide_out_top, R.anim.slide_in_top);
				Intent sent = new Intent(getApplicationContext(), Detial.class);
				
				startActivity(sent);
				//overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_left);
				overridePendingTransition(R.anim.slide_down, R.anim.slide_up);
				finish();
			}
		});

	}

	private void init() {
		// TODO Auto-generated method stub
		textViewWelcome = (TextView) findViewById(R.id.textViewWelcome);
		button = (Button) findViewById(R.id.button1);
	}



	public void AppExit() {
		Intent intent = new Intent(Intent.ACTION_MAIN);
		intent.addCategory(Intent.CATEGORY_HOME);
		intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		startActivity(intent);
		finish();
		System.exit(0);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onBackPressed() {
		// TODO Auto-generated method stub
		Log.i("Back", "");

	}

}
